package com.project.service;

import com.project.dao.SchoolManagerInfoMapper;
import com.project.entity.SchoolManagerInfo;
import com.project.service.base.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * author: WheelChen
 * date: 2017/7/25
 * <p>
 * 学院管理员服务
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class SchoolManagerInfoServiceImpl extends BaseService implements SchoolManagerInfoService {
    private static SchoolManagerInfoMapper schoolManagerInfoMapper = null;

    public void setMapper() {
        if (schoolManagerInfoMapper == null)
            schoolManagerInfoMapper = sqlSessionTemplate.getMapper(SchoolManagerInfoMapper.class);//1.获取相关mapper
    }

    /**
     * author: WheelChen
     * date: 2017/7/25
     * function: 根据userId查找对应字段
     *
     * @param userId
     * @return
     */
    @Override
    public SchoolManagerInfo findByUserId(Integer userId) {
        setMapper();
        return schoolManagerInfoMapper.selectByUserId(userId);
    }

    /**
     * author: WheelChen
     * date: 2017/7/31
     * function: 添加一个学院管理员
     *
     * @param schoolManagerInfo
     * @return
     */
    @Override
    public int addOne(SchoolManagerInfo schoolManagerInfo) {
        setMapper();
        return schoolManagerInfoMapper.insertSelective(schoolManagerInfo);
    }

    /**
     * author: WheelChen
     * date: 2017/9/18
     * function: 根据学院id查找单个学院
     *
     * @param schoolId
     * @return
     */
    @Override
    public SchoolManagerInfo findOneBySchoolId(Integer schoolId) {
        setMapper();
        return schoolManagerInfoMapper.selectOneBySchoolId(schoolId);
    }
}
